package com.ws.mapper;

import com.ws.domain.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrdersMapper {

    /**
     * 根据状态查询订单
     * @param status 订单状态
     * @return
     */
    @Select("<script>" +
            "select * from orders" +
            "<where>" +
            "<if test='status > 0 and status != null'>" +
            "and status = #{status}" +
            "</if>" +
            "</where>" +
            "</script>")
    List<Order> findOrderByStatus(@Param("status") Byte status);

    /**
     * 根据订单id更新订单状态
     * @param id 订单id
     * @param status 订单状态
     */
    @Update("update orders set status = #{status} where id = #{id}")
    void orderUpdate(@Param("id") int id, @Param("status") byte status);

    /**
     * 根据订单id删除订单
     * @param id 订单ID
     */
    @Delete("delete from orders where id = #{id}")
    void orderDelete(int id);
}
